﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    private Transform target;
    private Vector3 offest;
    private Vector2 velocity;

    

    private void Update()
    {
        if (target == null && GameManager.Instance.isGameControl)
        {
            target = GameObject.Find("Player").transform;
            offest = target.position - transform.position;
        }        
    }


    private void FixedUpdate()
    {
        if (target != null && GameManager.Instance.isGameControl)
        {
            float posX = Mathf.SmoothDamp(transform.position.x, target.position.x - offest.x, ref velocity.x, 0.05f);
            float posY = Mathf.SmoothDamp(transform.position.y, target.position.y - offest.y, ref velocity.y, 0.05f);
            if (posY > transform.position.y)
            {
                transform.position = new Vector3(posX,posY,transform.position.z);
            }            
        }
    }

}
